<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_thiessenAnalystGeometry_FGB"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
    <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
<div id="map" style="width: 100%;height:100%"></div>
<script type="text/javascript">
    var map, options,
        baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-changchun/rest/maps/长春市区图",
        serviceUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/spatialanalyst-changchun/restjsr/spatialanalyst";
    var extent = [48.4, -7668.25, 8958.85, -55.58];
    var projection = new ol.proj.Projection({
        code:'',
        extent: extent,
        units: 'm'
    });
    new ol.supermap.MapService(baseUrl).getMapInfo(function (serviceResult) {
        var mapJSONObj = serviceResult.result;
        map = new ol.Map({
            target: 'map',
            // ol v7版本用法为ol.control.defaults.defaults； v6版本以下用法为ol.control.defaults
            controls: ol.control.defaults.defaults({attributionOptions: {collapsed: false}})
                .extend([new ol.supermap.control.Logo({ link: "https://iclient.supermap.io" })]),
            view: new ol.View({
                center: [4503.6240321526, -3861.911472192499],
                zoom: 1,
                projection: projection,
                multiWorld: true
            })
        });
        options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
        var layer = new ol.layer.Tile({
            source: new ol.source.TileSuperMapRest(options)
        });
        map.addLayer(layer);
        thiessenAnalystProcess();
    });

    function thiessenAnalystProcess() {
        //创建几何泰森多边形参数
        var pointsList = [
            new ol.geom.Point([5238.998556, -1724.229865]),
            new ol.geom.Point([4996.270055, -2118.538477]),
            new ol.geom.Point([5450.34263, -2070.794081]),
            new ol.geom.Point([5317.70775, -2521.162355]),
            new ol.geom.Point([5741.149405, -1970.130198]),
            new ol.geom.Point([4716.133098, -1575.858795]),
            new ol.geom.Point([5447.671615, -2255.928819]),
            new ol.geom.Point([4783.423507, -1135.598744]),
            new ol.geom.Point([5472.712382, -2189.15344]),
            new ol.geom.Point([5752.716961, -2425.40363])
        ];

        var gThiessenAnalystParameters = new ol.supermap.GeometryThiessenAnalystParameters({
            points: pointsList
        });
        //创建泰森多边形服务实例
        new ol.supermap.SpatialAnalystService(serviceUrl).thiessenAnalysis(gThiessenAnalystParameters, 'FGB').then(function (serviceResult) {
            const vectorSource = new ol.source.FGB({
              url: serviceResult.result.newResourceLocation,
              strategy: ol.loadingstrategy.all,
            });

            resultLayer = new ol.layer.Vector({
              source: vectorSource,
              style: new ol.style.Style({
                    stroke: new ol.style.Stroke({
                        color: 'rgba(100, 100, 225, 10)',
                        width: 2
                    }),
                    fill: new ol.style.Fill({
                        color: 'rgba(0, 0, 255, 0.1)'
                    })
                })
            });
            map.addLayer(resultLayer);
        })
    }
</script>
</body>
</html>